<?php

class modifOeuvre extends Controller {


	function index()
	{
		$this->load->database();
		$this->load->library('form_validation');
		$this->load->helper('form');
		$this->load->helper('url');
		
		$data="";
		
		$query = $this->db->query("SELECT ID_Exposition, nom FROM exposition where utilisateur ='".$_COOKIE['login']."'");

		foreach ($query->result_array() as $row)
		{
			$data["expositions"][]=array($row['ID_Exposition'],$row['nom']);
		}
		
		$query = $this->db->query("SELECT ID_Media, chemin FROM media where type ='image' && oeuvre is NULL && utilisateur='".$_COOKIE['login']."'");
		
		foreach ($query->result_array() as $row)
		{
			$data["images"][]=array($row["ID_Media"],$row['chemin']);
		}
		
		$id=$this->input->post('selectNomOeuvre');
		
		if($id !=0){
		
		$query = $this->db->query('SELECT nom,presentation,descriptif, auteur,date_creation,lieu_creation,image_principale FROM oeuvre where ID_Oeuvre ='.$id);

		$row = $query->row();
		
			$data["nom"]=$row->nom;
			$data["descriptif"]=$row->descriptif;
			$data["presentation"]=$row->presentation;
			$data["auteur"]=$row->auteur;
			$data["periode"]=$row->date_creation;
			$data["pays"]=$row->lieu_creation;
			$data["id_image_principale"]=$row->image_principale;
			
			$query = $this->db->query('SELECT chemin FROM media where ID_Media ='.$row->image_principale);		
			$data["nom_image_principale"]=$query->row()->chemin;
			
			$query = $this->db->query('SELECT exposition FROM expose where oeuvre ='.$id);
			foreach ($query->result_array() as $row)
			{
				$data["expositionsOeuvre"][]=$row['exposition'];
			}
			
		
			$this->load->view('modifOeuvre',$data);
			
			
		
		}
		
		
		else {
		
		$this->load->view('modifOeuvre',$data);
		
		}
		
	}
	
	
}
?>
